package com.ruoyi.web.controller.manager.tool;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipUtil {

	/**
	 * 压缩文件
	 * @param fileToZip
	 * @param zipFilePath
	 * @param zos
	 */
	public static void zipFile(File fileToZip, String zipFilePath, ZipOutputStream zos) {
		try (FileOutputStream fos = new FileOutputStream(zipFilePath, true);
				FileInputStream fis = new FileInputStream(fileToZip);) {
			ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
			zos.putNextEntry(zipEntry);

			byte[] bytes = new byte[4096];
			int length;
			while ((length = fis.read(bytes)) >= 0) {
				zos.write(bytes, 0, length);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
